/**  
* <p>Title: RestTemplateTokenInterceptor.java</p>  
* <p>Description: </p>  
* <p>Copyright: Copyright (c) 2017</p>  
* <p>Company: http://www.richfit.com/</p>  
* @author Administrator
* @date 2020年3月13日  
* @version 1.0  
*/  
package com.rf.richfitwheel.admin.conf;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;

/**  
* <p>Title: RestTemplateTokenInterceptor</p>  
* <p>Description: </p>  
* @author Administrator  
* @date 2020年3月13日  
*/
@Component
public class RestTemplateTokenInterceptor implements ClientHttpRequestInterceptor {

	@Autowired
	private CommonPropertiesConfig commonPropertiesConfig;
	/* （非 Javadoc）
	 * <p>Title: intercept</p>  
	 * <p>Description: </p>  
	 * @param request
	 * @param body
	 * @param execution
	 * @return
	 * @throws IOException  
	 * @see org.springframework.http.client.ClientHttpRequestInterceptor#intercept(org.springframework.http.HttpRequest, byte[], org.springframework.http.client.ClientHttpRequestExecution)  
	 */
	@Override
	public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
			throws IOException {
		//增加自定义token
		HttpHeaders headers = request.getHeaders();
		headers.add("feignAccessToken", commonPropertiesConfig.getFeignAccessToken());
//       HttpEntity<String> requestEntity = new HttpEntity<String>(null, requestHeaders);
	    // 保证请求继续被执行
	    return execution.execute(request, body);
	}

}
